using System.ComponentModel.DataAnnotations;
using MediatR;
using SmartTracking.ErrorCode;

namespace BaseData.WriteApi.Appcontext.Command.Ewe_Files
{
    /// <summary>
    /// 母羊档案更新命令
    /// </summary>
    public class UpdateEweFileCommand : IRequest<ApiResult<bool>>
    {
        /// <summary>
        /// 母羊档案ID
        /// </summary>
        [Required]
        public int EweId { get; set; }

		/// <summary>
		/// 耳号
		/// </summary>
		[Required]
		public string EarSignal { get; set; } = string.Empty;
		/// <summary>
		/// 品种
		/// </summary>
		public int Variety { get; set; }
		/// <summary>
		/// 电子耳标号
		/// </summary>
		public string ElectronicEarTag { get; set; } = string.Empty;
		/// <summary>
		/// 基因等级
		/// </summary>
		public int GeneRank { get; set; }
		/// <summary>
		/// 父耳号
		/// </summary>
		public int FatherNumber { get; set; }
		/// <summary>
		/// 母耳号
		/// </summary>
		public int MotherNumber { get; set; }
		/// <summary>
		/// 出生日期
		/// </summary>
		public DateTime DateofBirth { get; set; }
		/// <summary>
		/// 入场日期
		/// </summary>
		public DateTime EntryDate { get; set; }
		/// <summary>
		/// 出生场地
		/// </summary>
		public int PlaceOfBirth { get; set; }
		/// <summary>
		/// 出生重量
		/// </summary>
		public int BirthWeight { get; set; }
		/// <summary>
		/// 备注
		/// </summary>
		public string Note { get; set; } = string.Empty;

		/// <summary>
		/// 验证命令参数
		/// </summary>
		/// <returns>验证结果</returns>
		public bool Validate(out string errorMessage)
        {
            errorMessage = string.Empty;

            if (EweId <= 0)
            {
                errorMessage = "母羊档案ID必须大于0";
                return false;
            }

            if (string.IsNullOrWhiteSpace(EarSignal))
            {
                errorMessage = "耳号不能为空";
                return false;
            }

            if (DateofBirth > DateTime.Now)
            {
                errorMessage = "出生日期不能晚于当前日期";
                return false;
            }

            if (EntryDate > DateTime.Now)
            {
                errorMessage = "入场日期不能晚于当前日期";
                return false;
            }

            if (BirthWeight <= 0 || BirthWeight > 500)
            {
                errorMessage = "出生重量必须大于0且小于500kg";
                return false;
            }

            if (GeneRank < 1 || GeneRank > 5)
            {
                errorMessage = "基因等级必须在1-5之间";
                return false;
            }

            return true;
        }
    }
}